package core.proto.timeline;

import static app.constants.CollabVizConstants.*;
import java.awt.Color;
import java.awt.Rectangle;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JTextArea;

import core.proto.Util;

import de.jaret.util.date.Interval;
import de.jaret.util.ui.timebars.TimeBarViewerDelegate;
import de.jaret.util.ui.timebars.swing.TimeBarViewer;
import de.jaret.util.ui.timebars.swing.renderer.DefaultTimeBarRenderer;

/**
 * Renders the intervals (aka annotations) on our timebar.
 * 
 *  @author Wei
 */
public class SavantIntervalRenderer extends DefaultTimeBarRenderer {

	final Color EDITING_COLOR = Color.white;
	final Color NOT_EDITING_COLOR = NOTE_COLOR;
	
	/** component used for rendering. */
	private JButton component;
	
	public SavantIntervalRenderer(){
		super();
		component = new JButton();
	}

	/**
	 * {@inheritDoc}
	 */
	public JComponent getTimeBarRendererComponent(TimeBarViewer tbv, Interval value, boolean isSelected,
			boolean overlapping) {
		return defaultGetTimeBarRendererComponent(tbv, value, isSelected, overlapping);
	}
	
	private void setColor(boolean isEditing) {
		if (isEditing) {
			component.setBackground(EDITING_COLOR);
		} else {
			component.setBackground(NOT_EDITING_COLOR);
		}
	}

	/**
	 * {@inheritDoc}
	 */
	public JComponent defaultGetTimeBarRendererComponent(TimeBarViewer tbv, Interval value, boolean isSelected,
			boolean overlapping) {
		AnnotationInterval interval = ((AnnotationInterval) value); 
		component.setText(interval.getAnnotationTxt());
		component.setToolTipText(interval.getAnnotationTxt());

		setColor(interval.isEditing());
		return component;
	}
}
